<template>
	<view class="user-space-head m-f-jcc">
		<image class="head-bg-img" :src="getBgImg" mode="aspectFill" lazy-load @tap.stop="changeBgImg"></image>
		<view class="user-space-head-info m-f-jcc m-f-column">
			<image class="head-info-img" :src="userinfo.userpic" mode="widthFix" lazy-load></image>
			<view class="head-nick user-space-margin m-f-ac">
				{{userinfo.username}}<tag-sex-age :sex="userinfo.sex" :age="userinfo.age"></tag-sex-age>
			</view>
			<view class="icon iconfont user-space-margin head-btn" :class="[isguanzhu?'active':'icon-jiahao']" @tap.stop="guanzhu">{{isguanzhu?'已关注':'关注'}}</view>
		</view>
	</view>
</template>

<script>
	import tagSexAge from '../common/tag-sex-age.vue'
	export default {
		props: {
			userinfo: {
				type: Object
			}
		},
		components: {
			tagSexAge
		},
		data() {
			return {
				isguanzhu: this.userinfo.isguanzhu
			}
		},
		computed: {
			getBgImg() {
				return '../../static/bgimg/' + this.userinfo.bgimg + '.jpg'
			}
		},
		methods: {
			changeBgImg() { // 切换背景
				let no = parseInt(this.userinfo.bgimg)
				if (no < 4) {
					no++
					this.userinfo.bgimg = no
				} else {
					no = 1
					this.userinfo.bgimg = no
				}
				
			},
			guanzhu() { // 关注
				this.isguanzhu = !this.isguanzhu
			}
		}
	}
</script>

<style lang="scss" scoped>
	.user-space-margin {
		margin: 15rpx 0;
	}
	.user-space-head {
		position: relative;
		height: 500rpx;
		overflow: hidden;
		.head-bg-img {
			width: 100%;
		}
		.user-space-head-info {
			position: absolute;
			top: 150rpx;
			.head-info-img {
				width: 150rpx;
				height: 150rpx;
				border-radius: 100%;
			}
			.head-nick {
				color: #FFFFFF;
				font-size: 35rpx;
				font-weight: bold;
				text-shadow: 2rpx 2rpx 10rpx #333333;
			}
			.head-btn {
				background: #FFE933;
				color: #333333;
				border: 1rpx solid #FFE933;
				padding: 0 15rpx;
				border-radius: 10rpx;
				font-size: 28rpx;
			}
			.active {
				background: none;
				color: #FFFFFF;
				border: 1rpx solid #FFFFFF;
			}
		}
	}
</style>
